package com.lq.whattoeattoday.config;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.lq.whattoeattoday.pojo.FoodPojo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

@Configuration
@Slf4j
public class SizeConfig
{

    /**
     * 家常菜
     *
     * @return
     */
    @Bean(name = "jiachangcai")
    public JSONArray jiachangcai()
    {
        JSONArray jiachangcai = JSONUtil.readJSONArray(new File("soure/jiachangcai.json"), Charset.defaultCharset());
        log.info("成功加载家常菜数据.." + (jiachangcai.size()));
        return jiachangcai;
    }

    /**
     * 川菜
     *
     * @return
     */
    @Bean(name = "chuancai")
    public JSONArray chuancai()
    {
        JSONArray chuancai = JSONUtil.readJSONArray(new File("soure/chuancai.json"), Charset.defaultCharset());
        log.info("成功加载川菜数据.." + (chuancai.size()));
        return chuancai;
    }


    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(connectionFactory);
        return template;
    }
}
